<template>
  <div>
    <div v-if="loginUser.id" class="app-main-panel ui-clear">
      <div class="app-aside-panel">
        <div class="app-user-avatar">
          <img :src="loginUser.avatarUrl" alt="" :title="loginUser.name">
        </div>
        <ul class="aside-menu-list">
          <li
            v-for="(item,i) in menus"
            :key="i"
            :class="{active:curMenu===item.name}"
            @click="curMenu=item.name"
          >
            <span :class="item.icon" :title="item.title" />
          </li>
        </ul>
      </div>
      <div class="app-container">
        <div v-show="curMenu==='chat'" class="app-container-panel ui-clear">
          <div class="app-user-panel">
            <div class="app-user-form">
              <span class="iconfont icon-search app-form-icon" />
              <input v-model="keyword" type="text" placeholder="搜索" class="app-form-element">
            </div>
            <div class="app-users-warp scroll">
              <div>
                <UserItem
                  v-for="(item,i) in searchUser(keyword)"
                  :key="i"
                  class="app-user-item"
                  :class="{active:item.id===curSession.id}"
                  :user="item"
                  :num="getUnReadNum(item.id)"
                  :message="getSessionLatestMsg(item.id)"
                  @click.native="changeSession(item)"
                >
                  <template v-if="getSessionLatestMsg(item.id).time" slot="time">
                    {{ getSessionLatestMsg(item.id).time | friendlyTime }}
                  </template>
                </UserItem>
              </div>
            </div>
          </div>
          <div class="app-session-panel">
            <UiSessionPanel
              v-if="curSession.id"
              :session="curSession"
              @sendMessage="sendMessage"
              @call-phone="callToUser"
            >
              <template slot="info">
                <span v-if="curSession.type==='group'" class="app-user-num">
                  ({{ users.length }})
                </span>
                <span v-if="curSession.type==='user'" class="app-use-extInfo">
                  <i class="iconfont" :class="curSession.deviceType==='pc'?'icon-pc':'icon-phone'" />
                  <span>({{ curSession.ip }})</span>
                </span>
              </template>
              <div slot="body" ref="message-list" class="message-list-warp scroll">
                <UiChatBubble
                  v-for="(item,i) in getMessages(curSession.id)"
                  :key="i"
                  class="message-item"
                  :message="item"
                  :setting="setting"
                  :is-send="loginUser.id===item.from.id"
                />
              </div>
            </UiSessionPanel>
            <div v-else class="app-no-session">
              <span class="iconfont icon-wechat" />
            </div>
          </div>
        </div>
        <div v-show="curMenu==='setting'" class="app-container-panel">
          <div class="app-card-panel">
            <div class="app-card-title">设置</div>
            <div class="app-user-card  ui-clear">
              <div class="app-card-avatar">
                <img :src="loginUser.avatarUrl" alt="">
              </div>
              <div class="app-card-container">
                <div class="app-card-infoRow">{{ loginUser.name }}</div>
                <div class="app-card-infoRow">
                  <i class="iconfont" :class="loginUser.deviceType==='pc'?'icon-pc':'icon-phone'" />
                  <span class="app-login-ip">{{ loginUser.ip }}</span>
                </div>
                <div class="app-card-infoRow">
                  <span class="app-login-time">{{ loginUser.time | formatTime }}</span>
                </div>
              </div>
            </div>
            <ul class="ui-list app-setting">
              <li>
                <span class="ui-label">消息声音</span>
                <UiSwitch v-model="setting.isVoice" class="ui-right" />
              </li>
              <li>
                <span class="ui-label">显示昵称</span>
                <UiSwitch v-model="setting.isName" class="ui-right" />
              </li>
              <li>
                <span class="ui-label">消息时间</span>
                <UiSwitch v-model="setting.isTime" class="ui-right" />
              </li>
            </ul>
          </div>
        </div>
        <div v-show="curMenu==='about'" class="app-container-panel">
          <div class="app-card-panel">
            <div class="app-card-title">关于</div>
            <ul class="ui-list app-setting">
              <li>
                <span class="ui-label">版本：</span>
                <span class="ui-text">{{ about.version }}</span>
              </li>
              <li>
                <span class="ui-label">协议：</span>
                <span class="ui-text">{{ about.license }}</span>
              </li>
              <li>
                <span class="ui-label">作者：</span>
                <span class="ui-text">{{ about.author }}</span>
              </li>
              <li>
                <span class="ui-label">邮箱：</span>
                <span class="ui-text">{{ about.email }}</span>
              </li>
              <li>
                <span class="ui-label">仓库：</span>
                <a class="ui-link" :href="about.github" target="_blank">GitHub</a>
              </li>
              <li>
                <a class="ui-link" :href="about.github" target="_blank">
                  <img src="https://img.shields.io/github/stars/cleverqin/node-websocket-Chatroom?label=Star&style=flat&logo=github" alt="">
                </a>
                <a class="ui-link" :href="about.github" target="_blank">
                  <img src="https://img.shields.io/github/forks/cleverqin/node-websocket-Chatroom?label=Fork&style=flat&logo=github" alt="">
                </a>
              </li>
            </ul>
          </div>
        </div>
      </div>
      <div class="rtc-container">
        <div v-show="isRing" class="call-modal-container">
          <div class="call-info">
            <img :src="from.avatarUrl" alt="">
            <div class="call-info-name">
              <div class="call-name">{{ from.name }}</div>
              <div class="call-text">{{ canAnswer ? '来自' + from.name + '视频电话' : '正在呼叫' + from.name + '...' }}</div>
            </div>
          </div>
          <div class="operate-container">
            <button v-if="canAnswer" class="operate-btn btn-answer" title="接听" @click="handleAnswer()">
              <img src="../../../assets/svg/phone-answer.svg" alt="">
            </button>
            <button class="operate-btn btn-hangup" title="挂断" @click="handleHangup()">
              <img src="../../../assets/svg/phone-hangup.svg" alt="">
            </button>
          </div>
        </div>
        <div v-show="isTalking" class="remote-video-container">
          <div class="connection-info-row">
            <span class="info-label">connect:</span>
            <span>{{ connectionState }}</span>
            <span class="info-label">ice:</span>
            <span>{{ iceConnectionState }}</span>
            <span class="info-label">message:</span>
            <span>{{ messageOpen }}</span>
          </div>
          <video id="remoteVideo" ref="remoteVideo" autoplay />
          <div class="operate-row">
            <button class="operate-btn btn-hangup" title="挂断" @click="handleHangup()" />
          </div>
          <input v-model="tips" class="tips-input" type="text">
          <div>
            <button class="btn" @click="getLocalTracksInfo()">获取Tracks信息</button>
          </div>
        </div>
      </div>
    </div>
    <UserLogin v-else @login="userLogin" />
    <audio ref="callAudio" src="../assets/ringback.wav" />
    <audio ref="audio" src="static/8400.mp3" />
    <canvas ref="canvas" width="280px" height="210px" style="display: none" />
  </div>
</template>

<script>
import UserItem from './UserItem'
import UiSessionPanel from './UiSessionPanel'
import UiChatBubble from './UiChatBubble'
import UserLogin from './UserLogin'
import UiSwitch from '../../../components/UiSwitch'
import { Manager } from 'socket.io-client'
import Message from '../../../components/Message'
import { friendlyTime, formatTime } from '../utils'
export default {
  name: 'UiChatApp',
  components: {
    UserItem,
    UiSessionPanel,
    UiChatBubble,
    UiSwitch,
    UserLogin
  },
  filters: {
    friendlyTime,
    formatTime
  },
  data() {
    return {
      menus: [
        {
          name: 'chat',
          icon: 'iconfont icon-comments',
          title: '会话'
        },
        {
          name: 'setting',
          icon: 'iconfont icon-cog',
          title: '设置'
        },
        {
          name: 'about',
          icon: 'iconfont icon-info',
          title: '关于'
        }
      ],
      curMenu: 'chat',
      users: [],
      curSession: {},
      keyword: '',
      messageData: {},
      setting: {
        isName: true,
        isTime: true,
        isVoice: true
      },
      about: {
        version: 'v1.0',
        license: 'MIT',
        author: 'cleverqin',
        email: '705597001@qq.com',
        github: 'https://github.com/cleverqin/node-websocket-Chatroom'
      },
      loginUser: {},
      deviceType: 'pc',
      audioSrc: './static/8400.mp3',
      socketURL: window._HOST || '',
      socket: null,
      isConnect: false,
      isRing: false,
      isTalking: false,
      callInfo: {
        caller: {},
        called: {}
      },
      connectionState: null,
      iceConnectionState: null,
      messageOpen: false,
      peerConnection: null,
      localMediaStream: null,
      remoteMediaStream: null,
      datachannel: null,
      callUser: null,
      token: null,
      defaultLocalStream: null,
      tips: '暂无音视频信号!'
    }
  },
  computed: {
    from() {
      return this.loginUser.id === this.callInfo.caller.id ? this.callInfo.called : this.callInfo.caller
    },
    canAnswer() {
      return this.loginUser.id === this.callInfo.called.id
    }
  },
  mounted() {
    this.initSocket()
    this.getDefaultLocalStream()
  },
  methods: {
    // 搜索用户
    searchUser(keyword) {
      const arr = []
      this.users.forEach((item) => {
        if ((item.name.indexOf(keyword) !== -1) || (item.id.indexOf(keyword) !== -1)) {
          arr.push(item)
        }
      })
      return arr
    },
    // 获取会话消息列表
    getMessages(sessionId) {
      if (sessionId && this.messageData[sessionId]) {
        return this.messageData[sessionId]
      }
      return []
    },
    // 添加消息到会话信息
    addSessionMessage(message, sessionId) {
      const vm = this
      if (!this.messageData[sessionId]) {
        this.$set(this.messageData, sessionId, [])
      }
      this.messageData[sessionId].push(message)
      if (this.curSession.id === sessionId) {
        setTimeout(() => {
          vm.scrollFooter('message-list')
        }, 16)
      }
      if (this.setting.isVoice && this.loginUser.id !== message.from.id) {
        this.playAudio()
      }
    },
    // 发送信息
    sendMessage(content, type, session) {
      const message = {
        from: this.loginUser,
        to: session,
        content: content,
        type: type,
        time: new Date().getTime(),
        isRead: true
      }
      this.addSessionMessage(message, session.id)
      if (this.socket) {
        this.socket.emit('message', message.from, message.to, message.content, message.type)
      }
    },
    // 获取最近一条会话信息
    getSessionLatestMsg(sessionId) {
      const messages = this.getMessages(sessionId)
      if (messages.length > 0) {
        return messages[messages.length - 1]
      }
      return {}
    },
    // 获取未读消息数量
    getUnReadNum(sessionId) {
      let num = 0
      const messages = this.getMessages(sessionId)
      if (messages.length === 0) {
        return num
      }
      messages.forEach((item) => {
        if (!item.isRead) {
          num++
        }
      })
      return num
    },
    // 设置会话消息已读
    setSessionRead(sessionId) {
      const messages = this.getMessages(sessionId)
      if (messages.length === 0) {
        return
      }
      messages.forEach((item) => {
        if (!item.isRead) {
          item.isRead = true
        }
      })
    },
    // 滚动到底部
    scrollFooter(name) {
      const $el = this.$refs[name]
      if ($el) {
        this.$nextTick(() => {
          $el.scrollTop = $el.scrollHeight
        })
      }
    },
    // 切换会话窗口
    changeSession(session) {
      const vm = this
      if (session.id === this.curSession.id) {
        return
      }
      this.setSessionRead(session.id)
      this.curSession = session
      setTimeout(() => {
        vm.scrollFooter('message-list')
      }, 16)
    },
    // 用户登录
    userLogin(value) {
      const user = Object.assign({}, value)
      if (!this.socket) {
        user.time = new Date().getTime()
        this.loginUser = user
      } else {
        this.socket.emit('login', user)
      }
    },
    // 播放消息音
    playAudio() {
      const $audio = this.$refs['audio']
      if ($audio) {
        $audio.play()
      }
    },
    // 初始SOCKET
    initSocket() {
      const _this = this
      const manager = new Manager(this.socketURL)
      const socket = manager.socket('/')
      this.socket = socket
      _this.socket.on('error', () => {
        console.log('出错了！！')
      })
      _this.socket.on('disconnect', (reason) => {
        this.isConnect = false
        console.log(reason + ' - disconnect')
      })
      _this.socket.io.on('reconnect_attempt', (attempt) => {
        console.info('重新尝试链接！！', attempt)
        _this.socket.io.opts.extraHeaders = {
          token: _this.token
        }
      })
      _this.socket.io.on('reconnect_failed', () => {
        console.warn('重新链接失败！')
      })
      _this.socket.io.on('reconnect', () => {
        console.info('重新链接成功！')
      })
      _this.socket.on('connect', (data) => {
        this.isConnect = true
        console.log('链接成功！', data)
      })
      _this.socket.on('loginSuccess', _this.loginSuccess)
      _this.socket.on('loginFail', _this.loginFail)
      _this.socket.on('message', _this.listenerMessage)
      _this.socket.on('system', _this.listenerSystem)
      _this.initRtcSocket()
    },
    // 登录成功
    loginSuccess(data, users) {
      console.log('loginSuccess', data)
      const _this = this
      _this.loginUser = data.user
      _this.token = data.token
      _this.users = users
    },
    // 登录失败
    loginFail(message) {
      Message.error(message)
    },
    // 监听信息事件
    listenerMessage(from, to, message, type) {
      const _this = this
      let isRead = false
      if (to.type === 'group') {
        if (_this.curSession.id === to.id) {
          isRead = true
        }
      } else {
        if (_this.curSession.id === from.id) {
          isRead = true
        }
      }
      const MESSAGE = {
        from: from,
        to: to,
        content: message,
        time: new Date().getTime(),
        type: type,
        isRead
      }
      this.addSessionMessage(MESSAGE, to.type === 'group' ? to.id : from.id)
    },
    // 监听系统事件
    listenerSystem(user, type) {
      console.log(user, type)
      const _this = this
      switch (type) {
        case 'join':
          _this.addUser(user)
          break
        case 'logout':
          _this.removeUser(user)
          break
        default:
          return
      }
    },
    // 用户上线了
    addUser(user) {
      const index = this.users.findIndex(item => item.id === user.id)
      if (index === -1) {
        this.users.push({ ...user })
      }
    },
    // 用户离线了
    removeUser(user) {
      const index = this.users.findIndex(item => item.id === user.id)
      if (index !== -1) {
        this.users.splice(index, 1)
      }
    },
    // 初始化RTCSocket事件
    initRtcSocket() {
      const _this = this
      // 用户接收当电话呼叫
      _this.socket.on('calling', (from) => {
        console.log(`来自${from.name}的呼叫`)
        _this.isRing = true
        _this.callUser = from
        _this.callInfo.caller = { ...from }
        _this.callInfo.called = { ..._this.loginUser }
      })
      // 监听用户同意会话连接
      _this.socket.on('calling-accept', async(from) => {
        _this.isRing = false
        const $callAudio = this.$refs['callAudio']
        $callAudio.pause()
        console.log(`用户${from.name}的同意会话`)
        // 创建让RTC
        const peerConnection = _this.createPeerConnection()
        _this.peerConnection = peerConnection
        _this.initStateChange(_this.peerConnection)
        _this.initDataChannel(_this.peerConnection, 'calling-accept')
        try {
          const localMediaStream = await navigator.mediaDevices.getUserMedia({ audio: true, video: true })
          _this.localMediaStream = localMediaStream
          localMediaStream.getTracks().map((track) => {
            peerConnection.addTrack(track, localMediaStream)
          })
        } catch (e) {
          console.log(e, '获取音视频权限出错了')
          Message.warning('获取音视频权限出错了')
          if (_this.defaultLocalStream) {
            _this.defaultLocalStream.getTracks().forEach((track) => {
              peerConnection.addTrack(track, _this.defaultLocalStream)
            })
          }
        }
        _this.isTalking = true
        _this.listenerIceAndTrack(peerConnection)
        // 创建offer并发送给被叫用户
        const offer = await peerConnection.createOffer()
        console.log('发送offer', offer)
        await peerConnection.setLocalDescription(offer)
        _this.socket.emit('offer', from, offer)
      })
      // 监听用户拒绝会话连接
      _this.socket.on('calling-refuse', (e) => {
        console.log(e)
        _this.callUser = null
        _this.isRing = false
        _this.localHangup()
      })
      // 用户收到offer创建answer发送给主叫用户
      _this.socket.on('offer', async(formUser, offer) => {
        console.log('收到offer', offer)
        // 创建让RTC
        const peerConnection = _this.createPeerConnection()
        _this.initStateChange(peerConnection)
        _this.peerConnection = peerConnection
        _this.initDataChannel(_this.peerConnection, 'offer')
        try {
          const localMediaStream = await navigator.mediaDevices.getUserMedia({ audio: true, video: true })
          _this.localMediaStream = localMediaStream
          localMediaStream.getTracks().forEach((track) => {
            peerConnection.addTrack(track, localMediaStream)
          })
        } catch (e) {
          console.log(e, '获取音视频权限出错了')
          Message.warning('获取音视频权限出错了')
          if (_this.defaultLocalStream) {
            _this.defaultLocalStream.getTracks().forEach((track) => {
              peerConnection.addTrack(track, _this.defaultLocalStream)
            })
          }
        }
        _this.isTalking = true
        _this.listenerIceAndTrack(peerConnection)
        await peerConnection.setRemoteDescription(offer)
        const answer = await peerConnection.createAnswer()
        await peerConnection.setLocalDescription(answer)
        console.log(peerConnection)
        _this.socket.emit('answer', formUser, answer)
      })
      // 主角用户收到answer后设置远端的SDP信息
      _this.socket.on('answer', async(formUser, answer) => {
        console.log('answer', answer)
        await _this.peerConnection?.setRemoteDescription(answer)
      })
      // 接受到ice信息
      _this.socket.on('ice-candidate', (formUser, candidate) => {
        console.log('candidate', candidate)
        _this.peerConnection?.addIceCandidate(candidate)
      })
    },
    // 监听RTC状态信息变更
    initStateChange(peerConnection) {
      peerConnection.onconnectionstatechange = (event) => {
        const connectionState = event.currentTarget.connectionState
        this.connectionState = connectionState
      }
      peerConnection.oniceconnectionstatechange = (event) => {
        const iceConnectionState = event.currentTarget.iceConnectionState
        this.iceConnectionState = iceConnectionState
      }
    },
    // 创建RTC连接
    createPeerConnection() {
      return new RTCPeerConnection({
        iceServers: [
          { urls: 'stun:stun.l.google.com:19302' }
        ]
      })
    },
    // 初始化消息通道
    initDataChannel(peerConnection) {
      this.datachannel = peerConnection.createDataChannel('messagechannel')
      console.log('this.datachannel', this.datachannel)
      this.datachannel.binaryType = 'arraybuffer'
      this.datachannel.onopen = (event) => {
        console.log('datachannel onopen', event)
        this.messageOpen = true
      }
      this.datachannel.onclose = function(event) {
        console.log('datachannel onclose', event)
      }
      this.datachannel.onmessage = (e) => {
        console.log('receive  Messages', e.data)
      }
      peerConnection.ondatachannel = (event) => {
        console.log(event)
        this.datachannel = event.channel
        this.datachannel.binaryType = 'arraybuffer'
        this.datachannel.onopen = (e) => {
          console.log('datachannel onopen', e)
          this.messageOpen = true
        }
        this.datachannel.onclose = (e) => {
          console.log('datachannel onclose', e)
        }
        this.datachannel.onmessage = (e) => {
          console.log('receive  Messages', e.data)
        }
      }
    },
    // 监听ice和track信息
    listenerIceAndTrack(peerConnection) {
      const _this = this
      peerConnection.ontrack = (event) => {
        console.log('收到远端音视频')
        _this.remoteMediaStream = event.streams[0]
        const remoteVideo = document.getElementById('remoteVideo')
        remoteVideo.srcObject = _this.remoteMediaStream
      }
      peerConnection.onicecandidate = (e) => {
        console.log(e)
        if (e.candidate) {
          const candidate = e.candidate
          console.log('candidate', candidate)
          _this.socket.emit('ice-candidate', _this.from, candidate)
        }
      }
    },
    // 本地连接挂断
    localHangup() {
      this.localMediaStream?.getTracks().forEach((track) => {
        track.stop()
      })
      this.isRing = false
      this.isTalking = false
      const $callAudio = this.$refs['callAudio']
      $callAudio.pause()
      this.peerConnection.close()
    },
    // 打视频电话给某用户
    callToUser(toUser) {
      if (this.isRing || this.isTalking) return
      console.log(`呼叫${toUser.name}`)
      this.socket.emit('calling', toUser)
      this.isRing = true
      this.callUser = toUser
      this.callInfo.caller = { ...this.loginUser }
      this.callInfo.called = { ...toUser }
      const $callAudio = this.$refs['callAudio']
      $callAudio.play()
    },
    // 接听来电
    handleAnswer() {
      this.socket.emit('calling-accept', this.from)
      this.isRing = false
    },
    // 挂断来电
    handleHangup() {
      this.socket.emit('calling-refuse', this.from)
      this.localHangup()
    },
    // 获取默认的本地视频流
    getDefaultLocalStream() {
      const canvas = this.$refs['canvas']
      const _this = this
      function draw() {
        requestAnimationFrame(draw)
        const canvasCtx = canvas.getContext('2d')
        const width = canvas.width
        const height = canvas.height
        canvasCtx.clearRect(0, 0, width, height) // 清除画布
        canvasCtx.fillStyle = 'rgb(224,225,228)' // 设置背景色（可选）
        canvasCtx.fillRect(0, 0, width, height)
        canvasCtx.font = 'bold 20px Arial'
        canvasCtx.fillStyle = '#27ae60'
        const textWidth = _this.tips.length * 20
        const x = width / 2 - textWidth / 2
        const y = height / 2
        canvasCtx.fillText(_this.tips, x, y)
      }
      draw()
      setTimeout(() => {
        const tracks = canvas.captureStream(25).getTracks()
        const stream = new MediaStream()
        tracks.forEach((track) => {
          stream.addTrack(track)
        })
        this.defaultLocalStream = stream
      }, 16)
    },
    getLocalTracksInfo() {
      const tracks = this.remoteMediaStream.getTracks()
      console.log(tracks)
    }
  }
}
</script>

<style scoped lang="less">
  .chat-app-warp{
    width: 100%;
    height: 100%;
    position: relative;
    background-image: url("https://cn.bing.com/th?id=OHR.LeMorneBrabant_ZH-CN9699020288_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp");
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
  }
  .ui-clear:after{
    display: block;
    content: '';
    clear: both;
  }
  .app-main-panel{
    width: 700px;
    height: 600px;
    background-color: #f2f2f2;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-left: -350px;
    margin-top: -300px;
  }
  .app-aside-panel{
    width: 60px;
    position: relative;
    height: 100%;
    float: left;
    background-color: #333333;
  }
  .app-user-avatar{
    padding: 10px;
  }
  .app-user-avatar img{
    width:40px;
    height: 40px;
    border-radius: 4px;
  }
  .aside-menu-list{
    list-style: none;
    padding: 0;
    margin: 0;
  }
  .aside-menu-list li{
    line-height: 40px;
    height: 40px;
    text-align: center;
    cursor: pointer;
  }
  .aside-menu-list li span{
    font-size: 22px;
    color: #f2f2f2;
  }
  .aside-menu-list li:hover span,
  .aside-menu-list li.active span{
    color: #b2e281;
  }
  .app-container{
    height: 100%;
    margin-left:60px;
  }
  .app-container-panel{
    position: relative;
    width: 100%;
    height: 100%;
  }
  .app-user-panel{
    width: 220px;
    height: 100%;
    position: relative;
    border-right: 1px solid #d1d1d1;
    background-color: #fcfcfc;
    box-sizing: border-box;
    float: left;
  }
  .app-users-warp{
    height: calc(100% - 60px);
    overflow-y: auto;
  }
  .app-user-item{
    cursor: pointer;
  }
  .app-user-item:hover{
    background-color: #f2f2f2;
  }
  .app-user-item.active{
    background-color: #ededed;
  }
  .app-session-panel{
    margin-left: 220px;
    height: 100%;
  }
  .app-warp{
    margin: 0 auto;
  }
  .message-list-warp{
    height: 100%;
    width: 100%;
    box-sizing: border-box;
    padding: 10px;
    overflow-y: auto;
  }
  .message-item:first-child{
    margin-top: 0;
  }
  .message-item{
    margin-top: 10px;
  }
  .app-user-form{
    height: 50px;
    box-sizing: border-box;
    padding: 10px;
    position: relative;
  }
  .app-form-icon{
    position: absolute;
    top: 10px;
    font-size: 18px;
    margin-left: 5px;
    height: 30px;
    color: #606266;
    line-height: 30px;
  }
  .app-form-element{
    height: 30px;
    font-size: 14px;
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px 8px 25px;
    border-radius: 15px;
    outline: none;
    border: none;
    background-color: #ebeef0;
    color: #666666;
  }
  .app-no-session{
    position: relative;
    width: 100%;
    height: 100%;
  }
  .app-no-session span.iconfont{
    position: absolute;
    display: block;
    width: 100px;
    height: 100px;
    top: 50%;
    left: 50%;
    text-align: center;
    line-height: 100px;
    vertical-align: middle;
    margin-top: -50px;
    margin-left: -50px;
    font-size: 100px;
    color: #e7e7e7;
  }
  .app-user-num{
    font-size: 12px;
    color: #666666;
  }
  .app-use-extInfo i.iconfont{
    display: inline-block;
    font-size: 18px;
    color: #0e8307;
    line-height: 30px;
    margin-right: 5px;
    position: relative;
    top: 2px;
  }
  .app-use-extInfo span{
    font-size: 12px;
    color: #666666;
  }
  .app-card-title{
    font-size: 16px;
    line-height: 40px;
    color: #333333;
    padding: 0 10px;
  }
  .app-user-card{
    padding: 10px;
    height: 60px;
  }
  .app-card-avatar{
    float: left;
    width: 60px;
    height: 60px;
    border-radius: 4px;
  }
  .app-card-avatar img{
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 4px;
  }
  .app-card-container{
    margin-left: 70px;
    height: 60px;
  }
  .app-card-infoRow{
    line-height: 20px;
    height: 20px;
  }
  .app-card-infoRow i.iconfont{
    font-size: 16px;
    color: #0e8307;
  }
  .app-login-ip{
    font-size: 14px;
    color: #666666;
    margin-left: 5px;
  }
  .app-login-time{
    font-size: 14px;
    color: #666666;
  }
  .app-setting{
    max-width: 400px;
  }
  .ui-list{
    list-style: none;
    padding: 0;
    margin: 0;
  }
  .ui-list li{
    line-height: 20px;
    height: 40px;
    border-bottom: 1px solid #d9dce0;
    padding: 10px;
    margin: 0 10px;
    box-sizing: border-box;
  }
  .ui-list li .ui-label{
    font-size: 14px;
    color: #333333;
  }
  .ui-right{
    float: right;
  }
  .ui-text{
    font-size: 14px;
    color: #666666;
  }
  .ui-link{
    font-size: 14px;
    color: #4792ff;
    text-decoration: none;
    margin-right: 5px;
  }
  /*定义滚动条宽高及背景，宽高分别对应横竖滚动条的尺寸*/
  .scroll::-webkit-scrollbar{
    width: 5px;
    height: 5px;
    background-color: rgba(255, 255, 255, 0.13);
  }
  /*定义滚动条的轨道，内阴影及圆角*/
  .scroll::-webkit-scrollbar-track{
    -webkit-box-shadow: inset 0 0 6px rgba(240, 240, 240, 0);
    border-radius: 10px;
    background-color: rgba(0, 89, 255, 0);
  }
  /*定义滑块，内阴影及圆角*/
  .scroll::-webkit-scrollbar-thumb{
    /*width: 10px;*/
    height: 20px;
    border-radius: 10px;
    -webkit-box-shadow: inset 0 0 6px rgba(236, 236, 236, 0.3);
    background-color: rgba(203, 203, 203, 0.54);
    transition: all 0.5s;
  }
  .rtc-container{
    position: absolute;
    left: 100%;
    top: 0;
    width: 280px;
    margin-left: 1px;
    .call-modal-container{
      display: flex;
      justify-content: space-between;
      background-color: #363741;
      border-radius: 4px;
      height: 40px;
      padding: 15px;
      .call-info{
        display: flex;
        img{
          width: 40px;
          height: 40px;
          border-radius: 4px;
          display: block;
          padding: 0;
          margin: 0;
        }
        .call-name{
          font-size: 14px;
          color: #eeeeee;
          line-height: 20px;
          margin-left: 10px;
        }
        .call-text{
          font-size: 12px;
          color: #eeeeee;
          line-height: 20px;
          margin-left: 10px;
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
          width: 110px;
        }
      }
      .operate-container{
        .operate-btn{
          font-size: 12px;
          width: 40px;
          height: 40px;
          border: none;
          outline: none;
          background-color: #666666;
          border-radius: 50%;
          text-align: center;
          line-height: 40px;
          color: #f2f2f2;
          cursor: pointer;
          position: relative;
          overflow: hidden;
          +.operate-btn{
            margin-left: 10px;
          }
          img{
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translateY(-50%) translateX(-50%);
          }
          &.btn-answer{
            background-color: #00D5AF;
            img{
              display: block;
              width: 24px;
              height: 24px;
            }
          }
          &.btn-hangup{
            background-color: #E0473A;
            img{
              display: block;
              width: 28px;
              height: 28px;
            }
          }
        }
      }
    }
    .remote-video-container{
      position: relative;
      background-color: #333333;
      border-radius: 4px;
      video{
        display: block;
        width: 100%;
        object-fit: cover;
      }
      .operate-row{
        text-align: center;
        padding: 5px 0;
        .operate-btn{
          font-size: 14px;
          width: 28px;
          height: 28px;
          border: none;
          outline: none;
          background-color: #666666;
          border-radius: 14px;
          text-align: center;
          line-height: 28px;
          color: #f2f2f2;
          cursor: pointer;
          +.operate-btn{
            margin-left: 10px;
          }
          &.btn-answer{
            background-color: #00D5AF;
            background-image: url(../../../assets/svg/phone-answer.svg);
            background-size: 20px 20px;
            background-position: center;
            background-repeat: no-repeat;
          }
          &.btn-hangup{
            background-color: #E0473A;
            background-image: url(../../../assets/svg/phone-hangup.svg);
            background-size: 20px 20px;
            background-position: center;
            background-repeat: no-repeat;
          }
        }
      }
      .connection-info-row{
        line-height: 30px;
        padding: 0 10px;
        font-size: 12px;
        color: #fff;
        .info-label{
          color: #fff;
        }
        span{
          margin-right: 2px;
        }
      }
      .tips-input{
        display: block;
        width: 100%;
        line-height: 32px;
        font-size: 14px;
        outline: none;
        box-sizing: border-box;
        border: 1px solid #d1d1d1;
        color: #333333;
        padding: 0 10px;
      }
    }
  }
</style>
